﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BT_DoHoa_Nhom13.DiagramFactorys;

namespace BT_DoHoa_Nhom13
{
    public abstract class MyShape
    {
        //Positions
        protected String name;
        protected int startX;
        protected int startY;
        protected int endX;
        protected int endY;
        protected Boolean isFill;

        public void Draw(MyGraphic graphic, List<MyEffect> effects)
        {
            if (effects == null)
            {
                ActualDraw(graphic);
            }
            else
            {
                List<MyEffect> bottomEffects = effects.Where(item => item.Kind == MyEffect.KIND.BOTTOM).ToList();
                DrawEffect(graphic,bottomEffects);

                ActualDraw(graphic);

                List<MyEffect> topEffects = effects.Where(item => item.Kind == MyEffect.KIND.TOP).ToList();
                DrawEffect(graphic, topEffects);
            }
        }

        protected virtual void DrawEffect(MyGraphic graphic, List<MyEffect> effects)
        {
            foreach(MyEffect effect in effects)
            {
                effect.Draw(graphic, this);
            }
        }

        protected abstract void ActualDraw(MyGraphic graphic);

        public abstract MyShape Clone();

        public virtual MyShape CloneByDiagramFactory(MyDiagramFactory factory)
        {
            return null;
        }

        public void Copy(MyShape origin)
        {
            this.SetStartPoint(origin.startX, origin.startY);
            this.SetEndPoint(origin.endX, origin.endY);
        }

        public virtual void SetStartPoint(int X, int Y)
        {
            startX = X;
            startY = Y;
        }

        public virtual void SetEndPoint(int X, int Y)
        {
            endX = X;
            endY = Y;
        }


        public void SetFill(Boolean fillState)
        {
            isFill = fillState;
        }

        public void SetConfig(out int top, out int left, out int width, out int height)
        {
            top = Math.Min(startY, endY);
            left = Math.Min(startX, endX);
            width = Math.Abs(startX - endX);
            height = Math.Abs(startY - endY);
        }

        public String GetName()
        {
            return name;
        }
    }
}
